package hu.myai.gui.widgets.graph;

import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;

public class SimpleGrid implements IGraphGrid {
    private Composite composite;

    private int columns;
    private int rows;

    private Color gridColor;

    public SimpleGrid(Composite composite) {
        this.composite = composite;
    }

    public Composite getComposite() {
        return composite;
    }

    public void setComposite(Composite composite) {
        this.composite = composite;
    }

    public int getColumns() {
        return columns;
    }

    public void setColumns(int columns) {
        this.columns = columns;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public Color getGridColor() {
        return gridColor;
    }

    public void setGridColor(Color gridColor) {
        this.gridColor = gridColor;
    }

    @Override
    public void paintGrid(PaintEvent e) {
        int w = composite.getSize().x;
        int h = composite.getSize().y;

        if (gridColor != null) {
            e.gc.setForeground(gridColor);
        }

        for (int i = 1; i < columns; i++) {
            int x = (i * w - 1) / columns;
            e.gc.drawLine(x, 0, x, h - 1);
        }
        for (int i = 1; i < rows; i++) {
            int y = (i * h - 1) / rows;
            e.gc.drawLine(0, y, w - 1, y);
        }
    }
}
